﻿<!DOCTYPE >
<html>
<head>
    <title>微街秀 > 选择区域</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <link rel="stylesheet" type="text/css" href="css/css.css">
    <script src="js/ajax-data.js" type="text/javascript"></script>
    <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="js/base.js" type="text/javascript"></script>
    <script src="js/dialog.js" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="js/sha.js" type="text/javascript"></script>
    <script src="js/sign.js" type="text/javascript"></script>
    <style type="text/css">
        .nicksave
        {
            width: 93%;
            margin-left: auto;
            line-height: 40px;
            margin-right: auto;
            height: 40PX;
            -webkit-border-radius: 10px;
            margin-top: 20%;
            border: #F37B0B 1px solid;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        <div class="wamtop">
            <div class="topleft" onclick="window.location.href='Makesh_4.html'">
                <img src="img/5.jpg" /></div>
            <div class="topcententxt">
                选择区域</div>
        </div>
        <div style="height: 100px; width: 90%; background: white; margin-top: 5px;margin: 20px auto 0 auto;" id="">
          
           
            <div style="margin-top:20px;">
                当前区域：<span class="area"></span>
             </div>
        </div>
        <div class="nicksave">
            <div style="color: #F37B0B; font-size: 20px;">
                <strong id="spanlocation">更新地理位置</strong></div>
        </div>
    </div>
<script>

    var area1="",area2="",area3="";
    $(document).ready(function () {
        LoadLocation();
        var param = {};
        AjaxStart("ajax/WxJsApiAccessToken.ashx?get", param, function (data) {
            if (data.code == 0) {
                var s = sign(data.item.JsApi_Ticket, location.href.split('#')[0]);
                console.log(s);
                wx.config({
                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。    
                    appId: data.item.AppId, // 必填，公众号的唯一标识    
                    timestamp: s.timestamp, // 必填，生成签名的时间戳    
                    nonceStr: s.nonceStr, // 必填，生成签名的随机串    
                    signature: s.signature,// 必填，签名，见附录1    
                    jsApiList: ['getLocation'] //获取地理位置接口  
                });
            }
            else
                Alert(data.msg);
        });
        

    });
    function renderReverse(data) {
        console.log(data);
        var addr = data.result.addressComponent;
        if (addr) {
            area1 = addr.province;
            area2 = addr.city;
            area3 = addr.district;
        }
        submits();
    }
    wx.ready(function () {
        $(".nicksave").bind("click", function () {
            $("#spanlocation").text("正在获取信息......");
            wx.getLocation({
                type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                success: function (res) {
                    var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                    var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                    var speed = res.speed; // 速度，以米/每秒计
                    var accuracy = res.accuracy; // 位置精度
                    var location = latitude + "," + longitude;
                    console.log(res);
                    var url = "http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location=" + location + "&output=json&pois=1&ak=RwwOB2yIpgl9ZpCg8uoqu2B7Vf5ELnVz";
                    $.getScript(url);
                    
                },
                fail: function (res) {
                    console.log(res);
                    Alert('获取地理位置失败！');
                }
            });
        });

    });
    wx.error(function (res) {
        Alert(res.errMsg);
    });
    

    function submits() {
        if (!islogin()) { window.location.href = 'login.html'; return; }
        if (!confirm("确定要更新定位吗?")) return;
        var param = "area1=" + area1 + "&area2=" + area2 + "&area3=" + area3;
        if (area1 == "" && area3 == "" && area3 == "") {
            Alert("定位获取失败,请重新进入页面");
            return;
        }
        AjaxStart("ajax/fc_setting.ashx?Setting", param, function (data) {
            if (data.code == 0) {
                Alert("更新成功")
                setTimeout(function () { window.location.href = "Makesh_4.html" }, 1000);
            }
            else
                Alert(data.msg);
        });
    }
    function LoadLocation() {
        AjaxStart("ajax/fc_setting.ashx?get",
            {}, function (data) {
            if (data.code == 0) {
                $(".area").html(data.item.area1 + data.item.area2 + data.item.area3);
            }
            else
                Alert(data.msg);
        });
        
    }
</script>
</body>
</html>
